home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-05-28 | 3.7 KB | 111 lines | [TEXT/CCL ] |
- ; rectangle manager
- ; from Smalltalk-80, the language and its implementation.
- ; Adele Goldberg and David Robson. Addison-Wesley, pp. 344-349
- ; implemented in Allegro Common Lisp by Jean-Pascal J. LANGE.
- ; © Copyright 1988 Jean-Pascal J. LANGE.
-
- (proclaim '(optimize (speed 3)
- (space 0)
- (safety 0)
- (compilation-speed 0) ))
-
- (eval-when
- (compile eval load)
- (require 'quickDraw)
- (require 'records) )
-
- (proclaim '(object-variable wptr)) ; from *window* class
-
- (deFun newRectangle
- (&key
- (top nil)
- (left nil)
- (topLeft nil)
- (bottom nil)
- (right nil)
- (bottomRight nil) )
- (let ((rectangle (make-record 'rect)))
- (if topLeft
- (cond (top
- (error "Conflicting coordinates: ~
- top (~A) and topLeft (~A)"
- top (point-string topLeft) ) )
- (left
- (error "Conflicting coordinates: ~
- left (~A) and topLeft (~A)"
- left (point-string topLeft) ) )
- (t (rSet rectangle rect.topLeft topLeft)) )
- (progn
- (if top (rSet rectangle rect.top top))
- (if left (rSet rectangle rect.left left)) ) )
- (if bottomRight
- (cond (bottom
- (error "Conflicting coordinates: ~
- bottom (~A) and bottomRight (~A)"
- bottom (point-string bottomRight) ) )
- (right
- (error "Conflicting coordinates: ~
- right (~A) and bottomRight (~A)"
- right (point-string bottomRight) ) )
- (t (rSet rectangle rect.bottomRight bottomRight)) )
- (progn
- (if bottom (rSet rectangle rect.bottom bottom))
- (if right (rSet rectangle rect.right right)) ) )
- rectangle ) )
-
- (deFun leftRightTopBottom (left right top bottom)
- (newRectangle :top top :left left :bottom bottom :right right) )
-
- (deFun originCorner (origin corner)
- (newRectangle :topLeft origin :bottomRight corner) )
-
- (deFun originExtent (origin extent)
- (newRectangle :topLeft origin
- :bottomRight (add-points origin extent) ) )
-
- (deFun originRect (rectangle)
- (rRef rectangle rect.topLeft) )
-
- (deFun corner (rectangle)
- (rRef rectangle rect.bottomRight) )
-
- (deFun center (rectangle)
- (let ((extent (extent rectangle)))
- (add-points (originRect rectangle)
- (make-point (round (point-h extent) 2.0)
- (round (point-v extent) 2.0) ) ) ) )
-
- (deFun extent (rectangle)
- (subtract-points (corner rectangle) (originRect rectangle)) )
-
- (deFun setOrigin (rectangle origin)
- (rSet rectangle rect.topLeft origin) )
-
- (deFun setCorner (rectangle corner)
- (rSet rectangle rect.bottomRight corner) )
-
- (deFun setCenter (rectangle aPoint)
- ; move the rectangle so it is centered on the point,
- ; but keep the width and height unchanged
- (let ((extent (extent rectangle)))
- (setOrigin rectangle
- (add-points (originRect rectangle)
- (subtract-points aPoint
- (center rectangle) ) ) )
- (setCorner rectangle
- (add-points (originRect rectangle) extent) ) ) )
-
- (deFun border (rectangle width &optional (window (front-window)))
- (let* ((oldPenState (ask window (pen-state))))
- (with-port (ask window wptr)
- (ask window (pen-normal)
- (set-pen-size (make-point width width))
- (frame-rect rectangle)
- (set-pen-state oldPenState) ) )
- (dispose-record oldPenState) ) )
-
- (deFun erase (rectangle &optional (window (front-window)))
- (ask window (erase-rect rectangle)) )
-
- (deFun invertRect (rectangle &optional (window (front-window)))
- (ask window (invert-rect rectangle)) )